import 'package:favor_cate/core/viewmodel/filter_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:favor_cate/core/extension/int_extension.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class FilterContent extends StatelessWidget {
  const FilterContent({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        buildChoiceText(context),
        buildChoiceSwitch()
      ],
    );
  }

  Widget buildChoiceText(BuildContext context){
    return Container(
      padding: EdgeInsets.all(40.px),
      child: Text("展示你的选择", style: Theme.of(context).textTheme.headline3!.copyWith(
        color: Colors.black,
        fontWeight: FontWeight.bold
      ),),
    );
  }

  Widget buildChoiceSwitch() {
    return Expanded(
      child: Consumer<FilterViewModel>(builder: (BuildContext context, model, Widget? child) {
        return ListView(
          children: [
            buildListTile(model.isGlutenFree, "无谷蛋白", "无谷蛋白", (value) => model.isGlutenFree = value),
            buildListTile(model.isLactoseFree, "不含乳糖", "不含乳糖", (value) => model.isLactoseFree = value),
            buildListTile(model.isVegan, "素食主义", "素食主义", (value) => model.isVegan = value),
            buildListTile(model.isVegetarian, "严格素食主义", "严格素食主义", (value) => model.isVegetarian = value),
          ],
        );

      },
      ),
    );

  }

  ListTile buildListTile(bool value, String title, String subtitle, Function(bool value) function) {
    return ListTile(
        title: Text(title),
        subtitle: Text(subtitle),
        trailing: Switch(value: value, onChanged: function),
      );
  }
}
